using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using WPFBPMN;
using System.Windows;

namespace WPFBPMN
{
    class BPMNException : Exception
    {
        public BPMNException(Exception exc,string additionalMessage)
        {
            if (additionalMessage == String.Empty)
            {
                additionalMessage = "An internal error occured.See ERROR.txt for more details";
            }
            if (exc != null)
            {
                StreamWriter writer = new StreamWriter("ERROR.txt", true);
                writer.WriteLine("Message:" + exc.Message);
                writer.WriteLine("StackTrace:" + exc.StackTrace);
                writer.WriteLine(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
                writer.WriteLine();
                writer.Flush();
                writer.Close();
            }
            ReportException(additionalMessage);
        }
        public  void ReportException(string additionalMessage)
        {
            Debug.WriteLine(additionalMessage);
            WindowMain wm = Application.Current.Windows[0] as WindowMain;
            if (wm != null)
            {
                wm.ReceiveNotification(additionalMessage);
            }
        }
    }
    
}
